#include "SCheat.h"
#include "IMemPatch.h"
#include "ExtendedVKeyCodes.h"

namespace TLib
{

	TRAINER_LIB_API SCheat::SCheat(const std::string& name,
		ITrainer* app,
		std::vector<IMemPatch*>& patches)
	{
		this->name = name;
		this->patches = patches;
		enabled = false;
		
		static int c = 0;
		hotkey = new HotKey(app->getTrainerHWnd(), VK_0+c, c, true);
		c++;
	}
	TRAINER_LIB_API SCheat::SCheat(const std::string& name,
		ITrainer* app,
		IMemPatch* patch)
	{
		this->name = name;
		patches.push_back(patch);
		enabled = false;

		static int c = 0;
		hotkey = new HotKey(app->getTrainerHWnd(), VK_0+c, c, true);
		c++;
	}
	TRAINER_LIB_API SCheat::SCheat(const std::string& name,
		ITrainer* app)
	{
		this->name = name;
		enabled = false;

		static int c = 0;
		hotkey = new HotKey(app->getTrainerHWnd(), VK_0+c, c, true);
		c++;
	}
	TRAINER_LIB_API SCheat::~SCheat()
	{
		for (unsigned int i = 0; i < patches.size(); i++)
		{
			delete patches[i];
		}
		delete hotkey;
	}
	TRAINER_LIB_API void SCheat::On(HANDLE hProcess)
	{
		enabled = true;
		for (unsigned int i = 0; i < patches.size(); i++)
		{
			patches[i]->Patch(hProcess);
		}
	}
	TRAINER_LIB_API void SCheat::Off(HANDLE hProcess)
	{
		enabled = false;
		for (unsigned int i = 0; i < patches.size(); i++)
		{
			patches[i]->UnPatch(hProcess);
		}
	}

	TRAINER_LIB_API HotKey* SCheat::getHotKey() const
	{
		return hotkey;
	}

	TRAINER_LIB_API void SCheat::gameTurnedOff()
	{
		enabled = false;
		for (unsigned int i = 0; i < patches.size(); i++)
		{
			patches[i]->gameTurnedOff();
		}
	}

}// Namespace TLib